# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Maintainer: Jonas Witschel <diabonas@archlinux.org>
# Contributor: Philipp A. <flying-sheep@web.de>

# Check if new updates break python-engineio

_pkgname=aiohttp
pkgname=python-aiohttp
_gitcommit=45b2c2c5773f0ee0d35fce8ff5716c78e91d9135
pkgver=3.9.0
pkgrel=1
pkgdesc='HTTP client/server for asyncio'
arch=('loong64' 'x86_64')
url='https://aiohttp.readthedocs.io'
license=('Apache')
depends=(
  'python'
  'python-aiosignal'
  'python-attrs'
  'python-frozenlist'
  'python-multidict'
  'python-yarl'
)
makedepends=(
  'cython'
  'git'
  'npm'
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-wheel'
)
checkdepends=(
  'gunicorn'
  'python-aiodns'
  'python-brotli'
  'python-proxy.py'
  'python-pytest'
  'python-pytest-mock'
  'python-pytest-xdist'
  'python-re-assert'
  'python-time-machine'
  'python-trustme'
  'python-uvloop'
)
optdepends=(
  'gunicorn: to deploy using Gunicorn'
  'python-aiodns: for fast DNS resolving'
  'python-brotli: for Brotli transfer-encodings support'
)
source=(
  "${pkgname}::git+https://github.com/aio-libs/aiohttp#commit=${_gitcommit}"
  git+https://github.com/nodejs/llhttp.git
)
sha512sums=('SKIP'
            'SKIP')

pkgver() {
  cd ${pkgname}
  git describe --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd ${pkgname}
  git submodule init
  git config submodule."vendor/llhttp".url "${srcdir}/llhttp"
  git -c protocol.file.allow=always submodule update --recursive
  sed 's|.install-cython ||' -i Makefile

  # This test calls the Python interpreter, we need to make sure that the path
  # for the C extensions is correct there as well
  sed -i "s/import {import_path!s}/import sys; sys.path.insert(0, '{os.environ['PYTHONPATH']}'); &/" \
      tests/test_circular_imports.py

  # Remove coverage testing
  sed -i '/--cov=/d' setup.cfg
}

build() {
  cd ${pkgname}
  make generate-llhttp cythonize
  python -m build --wheel --no-isolation
}

check() {
  cd ${pkgname}
  local _python_version=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
  mv tests/__init__.py{,.bak} # https://github.com/aio-libs/aiohttp/issues/7858
  mv tests/autobahn/test_autobahn.py{,.bak} # Docker tests
  PYTHONPATH="$PWD/build/lib.linux-$CARCH-cpython-${_python_version}" pytest
  mv tests/__init__.py{.bak,}
  mv tests/autobahn/test_autobahn.py{.bak,}
}

package() {
  cd ${pkgname}
  python -m installer --destdir="$pkgdir" dist/*.whl
}

# vim: ts=2 sw=2 et:
